home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4752 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  57 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.sprintlink.net!news1!news
  3. From: rclark@iquest.net (Robert B. Clark)
  4. Subject: Re: SYSTEM CALL in a while loop didn't work
  5. X-Nntp-Posting-Host: ind-007-237-42.iquest.net
  6. Message-ID: <31178e3b.14884@news.iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Internet, Inc.
  9. X-Newsreader: Forte Agent .99c/16.141
  10. References: <4f53vi$5uo@bcrkh13.bnr.ca>
  11. Date: Tue, 6 Feb 1996 17:38:49 GMT
  12.  
  13. On 5 Feb 1996 14:24:50 GMT, coopeng <coopeng@bnr.ca> wrote:
  14.  
  15. >while()
  16. >  while()
  17. >    */first system call */
  18. >    while()/*rubing*/
  19. >      strstr()
  20. >      */second system call */
  21. >
  22. >first system call works, but second doesn't.  If I comment the third while loop then 
  23. >second while loop also works.  I shall be thankful if you guys mail me the 
  24.  
  25. Can't really tell from the p-code you've posted--what you've written
  26. looks something like this:
  27.  
  28.     while()        /* Assume this evaluates to true...? */
  29.     {
  30.         while(system())
  31.             while(strstr());    
  32.     }
  33.     system();
  34.  
  35. The braces were implied in your code; I've added them here for clarity.
  36.  
  37. If this is what you have, the second system call will only run if the
  38. outermost while loop fails.  The first system call will run at least
  39. once if the outer while is met, and may very well fall into an infinite
  40. loop depending on its return value--system() returns 0 (false) if no
  41. error, -1 (true)  otherwise.
  42.  
  43. Since you said that the first system call executes, I can assume that
  44. the parameter expression for the outermost while evaluates to true--at
  45. least, initially.
  46.  
  47. The innermost while statement will either fail (strstr() returns NULL)
  48. or run indefinitely (strstr() returns char pointer to matched
  49. substring).
  50.  
  51. In short, I'm fairly certain that this is not what you meant, so could
  52. you post the actual code please?
  53. --
  54. Robert B. Clark <rclark@iquest.net>
  55. "Be wary of strong spirits.  It can make you shoot at tax collectors...
  56. and miss." --RAH
  57.